home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Amiga Format CD 38
/
Amiga Format CD38 (1999-03-15)(Future Publishing)(GB)(Track 1 of 3)[!][issue 1999-04].iso
/
-seriously_amiga-
/
archivers
/
amystp
/
amystpdecoder.c
< prev
next >
Wrap
C/C++ Source or Header
|
1999-01-25
|
4KB
|
137 lines
/* **************************************************************
* *
* STP Decoder Program *
* *
* Original version by: Mnp (unknown) *
* Amiga (optimized) version by: Manolis S Pappas *
* Thermopilon 24 *
* 14231 Nea Ionia *
* Athens GREECE *
* *
* E-mail: *
* mpappas@posidon.servienet.ariadne-t.gr *
* mpappas@acropolis.net *
* 2:410/128.19 *
* 39:250/3.19 *
**************************************************************
*/
/* Version 1.6b */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#define false(a) (((a)<32)||(((a)>123) && ((a)<179))||((a)>216))
#define R_MARGIN 65
#define VERSION "1.6c"
static const char CLI_VERS[]="$VER: AmySTP Decoder v1.6c "__AMIGADATE__;
int err(int e)
{
char *errlist[12];
errlist[0]="Cannot open input file";
errlist[1]="Cannot create output file";
errlist[3]="Cannot open input file";
errlist[4]="Cannot locate STP header";
errlist[5]="Cannot locate original Filename or Size";
errlist[6]="Cannot locate original num. of chars and checksum";
errlist[7]="Cannot create output file";
errlist[8]="Input file terminated too soon";
errlist[9]="Internal error";
errlist[10]="Checksums do not match";
fprintf(stderr,"Error(%d): %s\n",e,errlist[e-2]);
return e;
}
main(int argc,char *argv[])
{
FILE *fin, *fout;
unsigned char z=R_MARGIN,x,n=7,i,j,a,b[7],c[8],terminate=0;
unsigned int part=1,sum=1,l;
unsigned long checksum=0,fsize=0,chars=0,newsum=0;
char s[80]="",name[80]="";
char *string[5];
string[0]="START STP SCRIPT %u OF %u\n";
string[1]="FILENAME : %s - FILESIZE : %lu\n";
string[2]="CHARACTERS : %lu - CHECKSUM : %lX\n";
string[3]="\nEND STP SCRIPT\n";
string[4]="Successful. Checksum :";
if (argc<2)
{
fprintf(stderr,"\nAmySTP Binary Mail Decoder "__AMIGADATE__
".\nCopyright © 1994-97, Infinity Labs Development. All Rights Reserved.\n"
"Author: Manolis S. Pappas. Version: %s\n",VERSION);
fprintf(stderr,"\nUsage: %s [input text file] \n",argv[0]);
exit(4);
}
if ((fin=fopen(argv[1],"r"))==NULL) exit(err(5));
while (! fscanf(fin,string[0],&part,&sum))
{
fgets(s,80,fin);
if (feof(fin)) exit(err(6));
}
if (! fscanf(fin,string[1],name,&fsize))
exit(err(7));
if (! fscanf(fin,string[2],&chars,&checksum))
exit(err(8));
fprintf(stderr,"Now decoding %u of %u part(s)\n",part,sum);
fprintf(stderr,"Filename : %s - Original file size : %lu\n",name,fsize);
fprintf(stderr,"Characters : %lu - Checksum : %lX\n", chars,checksum);
if ((fout=fopen(name,"wb"))==NULL) exit(err(9));
do { c[0]=getc(fin); } while false(c[0]);
if (!chars--) terminate=1;
(c[0]>178)?(c[0]-=89):(c[0]-=33);
while (!terminate)
{
for (i=1;i<8;i++)
{
do
{
c[i]=getc(fin);
if (feof(fin))
{ remove(name);
exit(err(10));
}
} while false(c[i]);
if (!chars--) terminate=1;
if (terminate) n--;
else (c[i]>178)?(c[i]-=89):(c[i]-=33);
}
b[0]=(c[0]<<1)|(c[1]>>6);
b[1]=((c[1]&63)<<2)|(c[2]>>5);
b[2]=((c[2]&31)<<3)|(c[3]>>4);
b[3]=((c[3]&15)<<4)|(c[4]>>3);
b[4]=((c[4]& 7)<<5)|(c[5]>>2);
b[5]=((c[5]& 3)<<6)|(c[6]>>1);
b[6]=((c[6]& 1)<<7)|c[7];
for (i=0;i<n;i++)
{ putc(b[i],fout); newsum+=b[i]; }
do { c[0]=getc(fin); } while false(c[0]);
if (!chars--) terminate=1;
(c[0]>178)?(c[0]-=89):(c[0]-=33);
}
fclose(fout);
if (checksum!=newsum)
{
remove(name);
exit(err(12));
}
fprintf(stderr,"File Decoding %s %lX\n",string[4],newsum);
return 0;
}